<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>5.列表过滤_computed实现</title>
		<!-- 引入Vue -->
		<script type="text/javascript" src="../js/vue.js"></script>
	</head>
	<body>
		<!-- 准备好一个容器-->
		<div id="demo">
			<h2>人员列表</h2>
			<input type="text" placeholder="请输入姓名" v-model="keyword">
			<ul>
				<li v-for="p in fltPersons" :key="p.id">
					{{p.name}} - {{p.age}} - {{p.gender}}
				</li>
			</ul>
		</div>

		<script type="text/javascript">
			//阻止 vue 在启动时生成生产提示。
			Vue.config.productionTip = false
			
			new Vue({
				el:'#demo',
				data:{
					keyword:'',
					persons:[
						{id:'r6gy54',name:'马冬梅',age:18,gender:'女'},
						{id:'u87y8s',name:'周冬雨',age:19,gender:'女'},
						{id:'23ddsa',name:'周杰伦',age:20,gender:'男'},
						{id:'12dasd',name:'温兆伦',age:21,gender:'男'}
					]
				},
				computed:{
					fltPersons(){
						return this.persons.filter( p => p.name.indexOf(this.keyword) !== -1 )
					}
				}
			})
		</script>
	</body>
</html>